package com.sc.common.exception.handler;


import com.sc.common.exception.MessageTipException;
import com.sc.common.response.Response;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class MessageTipExceptionHandler {

    @ExceptionHandler(MessageTipException.class)
    public ResponseEntity<Response<String>> handleMessageTipException(MessageTipException e) {
        return ResponseEntity.status(HttpStatus.OK)
                .header("Content-Type", "application/json;charset=UTF-8")
                .header("Accept", "application/json;charset=UTF-8")
                .body(Response.fail(e.getMessage(), e.getCode()));
    }
}
